<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<form id="app_add_form" class="layui-form layuimini-form">

    <input type="hidden" id="id">
    <div class="layui-form-item">
        <label class="layui-form-label required">应用名称</label>
        <div class="layui-input-block">
            <input type="text" readonly name="appName" placeholder="请输入应用名称" lay-verify="required" lay-reqtext="应用名称不能为空" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">客户名称</label>
        <div class="layui-input-block">
            <input type="text" name="custName" placeholder="请输入客户名称" lay-verify="required" lay-reqtext="客户名称不能为空" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">客户联系人</label>
        <div class="layui-input-block">
            <input type="text" name="custContact" lay-verify="required" lay-reqtext="客户联系人不能为空"  placeholder="请输入客户联系人" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">联系方式</label>
        <div class="layui-input-block">
            <input type="text" name="custMobile" lay-verify="required" lay-reqtext="联系方式不能为空" placeholder="请输入联系方式" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
        </div>
    </div>
</form>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        const mobile = /^1[3|4|5|7|8]\d{9}$/,phone = /^0\d{2,3}-?\d{7,8}$/;
        form.verify({
            custMobile: function(value){
                var flag = mobile.test(value) || phone.test(value);
                if(!flag){
                    return '请输入正确联系方式';
                }
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let formData = data.field;
            formData.type = 'password';
            $.post("/user/add", formData, (rest) => {
                if (rest && "00" === rest.code) {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    return false;
                } else {
                    layer.msg(rest.msg);
                }
            });
            return false;
        });
        //监听提交
        form.on('submit(saveAndContinueBtn)', function (data) {
            let formData = data.field;
            formData.type = 'password';
            $.post("/user/add", formData, (rest) => {
                if (rest && "00" === rest.code) {
                    layer.msg(rest.msg);
                } else {
                    layer.msg(rest.msg);
                }
            });
            return false;
        });
    });

    var callbackData = function () {
        let dataArr = $("#app_add_form").serializeArray();
        let formData = {};
        dataArr.every( item => {
            formData[item.name] = item.value;
            return true;
        })
        return formData;
    }
</script>
</body>
</html>